package com.twp.imtest;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.util.Log;
import android.view.View;

import io.rong.imkit.RongIM;
import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.Message;
import io.rong.imlib.model.UserInfo;

public class MyApp extends Application {
    public static final String token1 = "ndoRIfHIEul00Y/uachGSMUdt/key1Xq7S0hu0lJ3kbxoKxzhgLqSgerjwlOlOdamgi675Y01avRmGpGaKKe2A==";
    public static final String token2 = "nnmPcOo15t9q/eyw9DPAjsUdt/key1Xq7S0hu0lJ3kbxoKxzhgLqSvdliSLfmvuHhbirmGfECpbRmGpGaKKe2A==";
    private static final String TAG = "twp";

    @Override
    public void onCreate() {
        super.onCreate();
        RongIM.init(this, "vnroth0kv8o8o");
        //设置会话界面的点击事件
        RongIM.setConversationClickListener(new RongIM.ConversationClickListener() {
            @Override
            public boolean onUserPortraitClick(Context context, Conversation.ConversationType conversationType,
                                               UserInfo userInfo, String targetId) {
                //用户头像被点击
                Log.e(TAG, "用户头像点击：id= " + userInfo.getUserId() + ",name=" + userInfo.getName());
                Log.e(TAG, "用户头像点击: 会话id= " + targetId);
                return true;
            }

            @Override
            public boolean onUserPortraitLongClick(Context context, Conversation.ConversationType conversationType,
                                                   UserInfo userInfo, String targetId) {
                //用户头像长按
                Log.e(TAG, "用户头像长按：id= " + userInfo.getUserId() + ",name=" + userInfo.getName());
                Log.e(TAG, "用户头像长按: 会话id= " + targetId);
                return true;
            }

            @Override
            public boolean onMessageClick(Context context, View view, Message message) {
                //消息体被点击
                Log.e(TAG, "消息体被点击："+message.getContent());
                return true;
            }

            @Override
            public boolean onMessageLinkClick(Context context, String link, Message message) {
                //消息中的链接点击
                return true;
            }

            @Override
            public boolean onMessageLongClick(Context context, View view, Message message) {
                //消息体长按
                Log.e(TAG, "消息体长按："+message.getContent().toString());
                return true;
            }
        });
    }

    public static String getCurProcessName(Context context) {
        int pid = android.os.Process.myPid();
        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {
            if (appProcess.pid == pid) {
                return appProcess.processName;
            }
        }
        return null;
    }
}
